package com.xdf.xzymanagementsystem.controller;

import com.xdf.xzymanagementsystem.base.BaseController;
import com.xdf.xzymanagementsystem.dto.ExcelInputParamDTO;
import com.xdf.xzymanagementsystem.enums.MenuConstant;
import com.xdf.xzymanagementsystem.enums.OperateConstant;
import com.xdf.xzymanagementsystem.enums.ResponseEnum;
import com.xdf.xzymanagementsystem.enums.SeparatorConstant;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.util.Assert;
import org.springframework.web.bind.annotation.*;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import com.xdf.xzymanagementsystem.entity.ResponseResult;

import java.util.List;

import com.xdf.xzymanagementsystem.entity.CurrencyType;
import com.xdf.xzymanagementsystem.service.CurrencyTypeService;
import org.springframework.web.multipart.MultipartFile;

import javax.servlet.http.HttpServletRequest;

/**
 * @Description : 自动生成的控制层
 * @Author : 张柯
 * @Date : 2021-04-14 09:25:22
 */
@Api(tags = "币种")
@CrossOrigin
@RestController
@RequestMapping("/currencyType")
public class CurrencyTypeController extends BaseController {
    @Autowired
    private CurrencyTypeService service;

    /**
     * @Description : 选择新增
     * @Return : ResponseResult<Void>
     * @Author : 张柯
     * @Date : 2021-04-14 09:25:22
     */
    @ApiOperation(value = "选择新增", httpMethod = "POST", notes = "自动生成的新增方法")
    @RequestMapping(value = "/insertSelective", method = RequestMethod.POST)
    @RequiresPermissions(MenuConstant.MENU408 + SeparatorConstant.SEPARATOR + OperateConstant.ADD)
    public ResponseResult<Void> insertSelective(CurrencyType record) throws Exception {
        service.insertSelective(record);
        return ResponseResult.<Void>builder().success(true).message(ResponseEnum.OK.getName()).build();
    }

    /**
     * @Description : 选择修改
     * @Return : CurrencyType
     * @Author : 张柯
     * @Date : 2021-04-14 09:25:22
     */
    @ApiOperation(value = "选择修改", httpMethod = "PUT", notes = "自动生成的修改方法")
    @RequestMapping(value = "/updateSelective", method = RequestMethod.POST)
    @RequiresPermissions(MenuConstant.MENU408 + SeparatorConstant.SEPARATOR + OperateConstant.MODIFY)
    public ResponseResult<Void> updateSelective(CurrencyType record) throws Exception {
        service.updateByPrimaryKeySelective(record);
        return ResponseResult.<Void>builder().success(true).message(ResponseEnum.OK.getName()).build();
    }

    /**
     * @Description : 根据主键查询
     * @Return : CurrencyType
     * @Author : 张柯
     * @Date : 2021-04-14 09:25:22
     */
    @ApiOperation(value = "根据主键查询", httpMethod = "GET", notes = "自动生成的查询方法")
    @RequestMapping(value = "/queryByPk/{id}", method = RequestMethod.GET)
    public CurrencyType selectByPrimaryKey(@PathVariable("id") String id) throws Exception {
        if (id == null) return null;
        return service.selectByPrimaryKey(id);
    }

    /**
     * @Description : 查询方法
     * @Return : java.util.List
     * @Author : 张柯
     * @Date : 2021-04-14 09:25:22
     */
    @ApiOperation(value = "查询方法", httpMethod = "GET", notes = "自动生成的查询方法")
    @RequestMapping(value = "/listQuery", method = RequestMethod.GET)
    public List<CurrencyType> query(CurrencyType record) throws Exception {
        return service.listQuery(record);
    }

    /**
     * @Description : 根据主键删除方法
     * @Return : ResponseResult<Void>
     * @Author : 张柯
     * @Date : 2021-04-14 09:25:22
     */
    @ApiOperation(value = "根据主键删除方法", httpMethod = "DELETE", notes = "自动生成的删除方法")
    @RequestMapping(value = "/deleteByPk", method = RequestMethod.POST)
    @RequiresPermissions(MenuConstant.MENU408 + SeparatorConstant.SEPARATOR + OperateConstant.DELETE)
    public ResponseResult<Void> deleteByPrimaryKey(@RequestParam("id") String id) throws Exception {
        service.deleteByPrimaryKey(id);
        return ResponseResult.<Void>builder().success(true).message(ResponseEnum.OK.getName()).build();
    }

    /**
     * 导入方法
     *
     * @param file    文件
     * @param param   参数
     * @param request 请求
     * @return
     * @throws Exception
     */
    @ApiOperation(value = "导入方法", httpMethod = "POST", notes = "导入方法")
    @RequestMapping(value = "/upload", method = RequestMethod.POST)
    @RequiresPermissions(MenuConstant.MENU408 + SeparatorConstant.SEPARATOR + OperateConstant.ADD)
    public ResponseResult<Void> upload(MultipartFile file, ExcelInputParamDTO param, HttpServletRequest request) throws Exception {
        Assert.notNull(file, "文件未上传!");
        service.upload(file, param, request);
        return ResponseResult.<Void>builder().success(true).message(ResponseEnum.OK.getName()).build();
    }
}